#ifndef CAN_H
#define CAN_H
#include "board.h"
#include "hpm_mcan_drv.h"

/* 新增的CAN通道定义 */

#define CAN_CHANNEL_4 HPM_MCAN4  // 原有的CAN4基地址
#define CAN_CHANNEL_3 HPM_MCAN3
#define CAN_CHANNEL_2 HPM_MCAN6  //通道2对应着 先辑can6
#define CAN_CHANNEL_1 HPM_MCAN0  // 假设这是CAN0的基地址




typedef struct {
    MCAN_Type *can_base;
    uint32_t clock_freq;
    uint32_t irq_num;
} can_info_t;

static can_info_t s_can_info[] = {
#if defined(HPM_MCAN0)
    { .can_base = HPM_MCAN0, .irq_num = IRQn_MCAN0 },
#endif
#if defined(HPM_MCAN1)
    { .can_base = HPM_MCAN1, .irq_num = IRQn_MCAN1 },
#endif
#if defined(HPM_MCAN2)
    { .can_base = HPM_MCAN2, .irq_num = IRQn_MCAN2 },
#endif
#if defined (HPM_MCAN3)
    { .can_base = HPM_MCAN3, .irq_num = IRQn_MCAN3 },
#endif
#if defined (HPM_MCAN4)
    { .can_base = HPM_MCAN4, .irq_num = IRQn_MCAN4 },
#endif
#if defined (HPM_MCAN5)
    { .can_base = HPM_MCAN5, .irq_num = IRQn_MCAN5 },
#endif
#if defined (HPM_MCAN6)
    { .can_base = HPM_MCAN6, .irq_num = IRQn_MCAN6 },
#endif
#if defined (HPM_MCAN7)
    { .can_base = HPM_MCAN7, .irq_num = IRQn_MCAN7 },
#endif
};



// 带ID参数的CAN发送函数
hpm_stat_t send_data_to_can_with_id(const uint8_t *data, uint8_t length, 
                                  uint16_t can_id, uint8_t channel, bool *ok);

// 带ID参数的CANFD发送函数
hpm_stat_t send_data_to_canfd_with_id(const uint8_t *data, uint32_t length, 
                                    uint32_t can_id, uint8_t channel, bool *ok);

// 将UART数据分割成CAN帧发送
void send_uart_data_to_can(uint8_t* data, uint16_t data_len, 
                          uint16_t start_id, uint8_t channel);

// 将UART数据分割成CANFD帧发送
void send_uart_data_to_canfd(uint8_t* data, uint32_t data_len, 
                            uint32_t start_id, uint8_t channel);



#endif /* CAN_H */